package com.pixiv.service.Impl;

import com.pixiv.DAO.LoginMapping;
import com.pixiv.DAO.TitleMapping;
import com.pixiv.DAO.UserMapping;
import com.pixiv.Entity.TitlePicture;
import com.pixiv.Entity.User;
import com.pixiv.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapping userMapping;
    @Autowired
    private LoginMapping loginMapping;
    @Autowired
    private TitleMapping titleMapping;

    public String getUserIconByUserID(int id)
    {
        return userMapping.getUserIconByUserID(id);
    }

    @Override
    public void updateSexByUserID(String sex, int userid) {
        userMapping.updateSexByUserID(sex,userid);
    }

    public User flshUserData(User user){
        int userid = user.getUserID();
        user.setName( userMapping.getNameByID(userid) );
        user.setEMail( userMapping.getEMailByID(userid) );
        user.setPhone( userMapping.getPhoneByID(userid ));
        user.setQQ( userMapping.getQQByID(userid) );
        user.setSex( userMapping.getSexByID(userid));
        user.setLevel( userMapping.getUserLevelByUserID(userid) );
        user.setExplosion( userMapping.getUserExplosionByUserID(userid) );
        user.setUserType( userMapping.getUserTypeByUserID(userid) );
        return user;

    }

    @Override
    public void updatePhaseInforByUserID(String name, String sex, String email, String qq, String phone, int UserID) {
        userMapping.updatePhaseInforByUserID(name,sex,email,qq,phone,UserID);
    }

    @Override
    public void updateUserIconPathByUserID(int id, String path) {
        if (loginMapping.getUserIconSizeIDByUserID(id) > 0) {
            userMapping.updateUserIconPathByUserID(id, path);
        }else{
            loginMapping.insertUserIconPathByUserID(id,path);
        }
    }

    @Override
    public User getUser(int userid) {
        return userMapping.getUser(userid);
    }

    public int getTitleTotal(int userid)
    {
        return userMapping.getTitleTotal(userid);
    }

    public List<TitlePicture> getUserTitles(int userid){
        return titleMapping.getUserTitles(userid);
    }


}
